package com.mall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.utils.PageUtils;
import com.mall.common.utils.Query;

import com.mall.dao.SpuImagesDao;
import com.mall.entity.SpuImages;
import com.mall.service.SpuImagesService;


@Service("spuImagesService")
public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesDao, SpuImages> implements SpuImagesService {


    @Autowired
    private SpuImagesDao spuImagesDao;


    /**
     * 保存images
     * @param catId
     * @param images
     */
    @Override
    public void saveImages(Long id, List<String> images) {
        if (images == null || images.size() == 0){

        }else {
            List<SpuImages> collect = images.stream().map(img -> {
                SpuImages spuImage = new SpuImages();
                spuImage.setSpuId(id);
                spuImage.setImgUrl(img);

                return spuImage;
            }).collect(Collectors.toList());
            this.saveBatch(collect);
        }
    }

    @Override
    public List<SpuImages> listImages(Integer id) {
        List<SpuImages> spuImages = spuImagesDao.listAllBySpuIdList(id);
        return spuImages;
    }

//    @Override
//    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<SpuImages> page = this.page(
//                new Query<SpuImages>().getPage(params),
//                new QueryWrapper<SpuImages>()
//        );
//
//        return new PageUtils(page);
//    }



}